﻿using Libs;
using System.IO;

namespace WriteForFighting.Game.Asset
{
    static class Drawable
    {
        public static int[] Players { get; private set; }
        public static int[] Bullets { get; private set; }
        public static int IconOpen { get; private set; }
        public static int IconPlay { get; private set; }
        public static int IconStop { get; private set; }
        public static int[] EffectExplosion { get; private set; }
        public static int[] EffectSmallExplosion { get; private set; }

        private const string LoadWrongMessage = "ファイルの読み込みに失敗しました。";
        private const string GraphExtension = ".png";

        public static void Init()
        {
            {
                Players = new int[2];
                const string path = GD.ASSET_DIR + @"graph\player" + GraphExtension;
                if (DX.LoadDivGraph(path, 2, 1, 1, 60, 60, out Players[0]) == -1)
                {
                    throw new FileLoadException(LoadWrongMessage, path);
                }
            }

            {
                Bullets = new int[5];
                const string temppath = GD.ASSET_DIR + @"graph\bullets\bullet";
                for (int i = 0; i < 5; ++i)
                {
                    string path = temppath + i + GraphExtension;

                    Bullets[i] = DX.LoadGraph(path);
                    if (Bullets[i] == -1)
                    {
                        throw new FileLoadException(LoadWrongMessage, path);
                    }
                }
            }

            {
                const string path = GD.ASSET_DIR + @"graph\icons\open" + GraphExtension;
                IconOpen = DX.LoadGraph(path);
                if (IconOpen == -1)
                {
                    throw new FileLoadException(LoadWrongMessage, path);
                }
            }

            {
                const string path = GD.ASSET_DIR + @"graph\icons\play" + GraphExtension;
                IconPlay = DX.LoadGraph(path);
                if (IconPlay == -1)
                {
                    throw new FileLoadException(LoadWrongMessage, path);
                }
            }

            {
                const string path = GD.ASSET_DIR + @"graph\icons\stop" + GraphExtension;
                IconStop = DX.LoadGraph(path);
                if (IconStop == -1)
                {
                    throw new FileLoadException(LoadWrongMessage, path);
                }
            }

            {
                EffectExplosion = new int[7];
                const string path = GD.ASSET_DIR + @"graph\effects\explosion" + GraphExtension;
                if (DX.LoadDivGraph(path, 7, 7, 1, 60, 60, out EffectExplosion[0]) == -1)
                {
                    throw new FileLoadException(LoadWrongMessage, path);
                }
            }

            {
                EffectSmallExplosion = new int[7];
                const string path = GD.ASSET_DIR + @"graph\effects\smallexplosion" + GraphExtension;
                if (DX.LoadDivGraph(path, 7, 7, 1, 60, 60, out EffectSmallExplosion[0]) == -1)
                {
                    throw new FileLoadException(LoadWrongMessage, path);
                }
            }
        }
    }
}
